using System;
using System.Collections.Generic;
using Project3D.my3D.Base;

namespace Project3D.my3D.Structure
{

    public class myFace
    {
        //Extra variable. Useful in algorithms for storing extra information for a face.
        public int f_id;

        //Link to any adjacent halfedge to this face.
        public myHalfedge adjacent_halfedge;

        public myFace()
        {
            f_id = 0;
            adjacent_halfedge = null;
        }

        public myFace Copy()
        {
            myFace tmp = new myFace();
            tmp.f_id = this.f_id;

            return tmp;
        }

        public myVector3D GetNormal()
        {
            if (adjacent_halfedge == null) return new myVector3D();

            myVector3D normal = new myVector3D();

            myUtil.computeNormal(adjacent_halfedge.source, adjacent_halfedge.target , adjacent_halfedge.next.target, normal);

            normal.normalize();

            return normal;
        }

        public myVertex GetCentroid(int id = -1)
        {
            List<myPoint3D>  listOfPoint = new List<myPoint3D>();
            myVertex centroid = new myVertex();
            myHalfedge edge = this.adjacent_halfedge;

            do
            {
                listOfPoint.Add(edge.source.point);
                edge = edge.next;
            } while (edge != this.adjacent_halfedge);

            centroid.setPoint(myPoint3D.CentroidPoint(listOfPoint.ToArray()));

            return centroid;
        }

    }

}
